﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Infrastructure.Aspect.Services.Serialization
{
    public class XmlService: ISerializationService
    {
        public byte[] Serialization(object target)
        {
            var ser = new XmlSerializer(target.GetType());
            using (var mem = new System.IO.MemoryStream())
            {
                ser.Serialize(mem, target);
                mem.Flush();
                return mem.ToArray();
            }
        }

        public T DesSerialization<T>(byte[] target)
        {
            var ser = new XmlSerializer(typeof(T));
            using (var mem = new System.IO.MemoryStream(target))
            {
                return (T)ser.Deserialize(mem);                
            }
        }
    }
}
